//
//  ViewController.swift
//  FlutterBoostIOSDemo
//
//  Created by wangliang on 2024/4/23.
//

import UIKit
import SnapKit
import flutter_boost

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        let button1 = UIButton(type: .system)
        button1.setTitle("原生页面 -> Flutter 返回数据", for: .normal)
        button1.addTarget(self, action: #selector(jumpPage1), for: .touchUpInside)
        view.addSubview(button1)
        button1.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(90)
            make.leading.equalToSuperview().offset(20)
        }
        
        // button2
        let button2 = UIButton(type: .system)
        button2.setTitle("原生页面 -> Flutter 日历页面", for: .normal)
        button2.addTarget(self, action: #selector(jumpPage2), for: .touchUpInside)
        view.addSubview(button2)
        button2.snp.makeConstraints { make in
            make.top.equalTo(button1.snp.bottom).offset(20)
            make.leading.equalToSuperview().offset(20)
        }
        
        let button3 = UIButton(type: .system)
        button3.setTitle("原生页面 -> 原生页面 Test页面", for: .normal)
        button3.addTarget(self, action: #selector(jumpPageTest), for: .touchUpInside)
        view.addSubview(button3)
        button3.snp.makeConstraints { make in
            make.top.equalTo(button2.snp.bottom).offset(20)
            make.leading.equalToSuperview().offset(20)
        }
    }
    
    @objc func jumpPage1() {
        let options = FlutterBoostRouteOptions()
        options.pageName = FlutterBoostAgent.flutterMainPage
        options.arguments = ["title": "MainPage"]
        options.onPageFinished = { result in
            NSLog("WLTest [Native -> Flutter] 返回数据: \(result)")
        }
        FlutterBoostAgent.shared.openFlutterRoute(self.navigationController, options: options)
    }
    
    @objc
    private func jumpPage2() {
        let options = FlutterBoostRouteOptions()
        options.pageName = FlutterBoostAgent.flutterCalendarPage
        options.arguments = ["title": "SimplePage"]
        options.onPageFinished = { result in
            NSLog("WLTest [Native -> Flutter] 返回数据: \(result)")
        }
        FlutterBoostAgent.shared.openFlutterRoute(self.navigationController, options: options)
    }
    
    @objc
    private func jumpPageTest() {
        self.navigationController?.pushViewController(TestViewController(), animated: true)
    }


}

